package thread.synchronizedtest;

import java.util.concurrent.CountDownLatch;

public class Test {
    private static Integer count = 0;

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10000);
        Test test = new Test();
        for (int i = 0; i < 10000; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    test.add();
                    countDownLatch.countDown();
                }
            });
            thread.start();
        }
        countDownLatch.await();
        System.out.println(count);
    }

    public static synchronized void add() {
        count++;
    }
}
